let webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
console.log(`==============NODE_ENV is ${process.env.NODE_ENV},webpack is running...==============`);
let watchFlag = true;
if (process.env.NODE_ENV != 'production') {
    watchFlag = false;
}
module.exports = {
    entry: {
        entry:__dirname + '/src/router/index.jsx',//入口函数
        //vendor: ['react', 'react-dom', 'moment'...]//公用模块,没有人话不要写入
    },
    output: {
        path:  __dirname + '/www/static/js/',
        filename: '[name].min.js'
    },
    module: {
        loaders: [
            {test: /\.jsx$/,loader: 'babel-loader?' + JSON.stringify({presets: ['react', 'es2015',"stage-1"],plugins: ["transform-decorators-legacy"]}),exclude: /node_modules/,include: __dirname},
            {test: /\.es6$/,loader: 'babel-loader',query: {presets: ['es2015',"stage-1"],plugins: ["transform-decorators-legacy"]}},
            {test: /\.less$/, loader:ExtractTextPlugin.extract({use:['css-loader?sourceMap','autoprefixer-loader?{browsers: ["last 2 version", "firefox 15"]}',"less-loader?sourceMap"],fallback:'style-loader'})},
            {test: /\.css$/, loader:ExtractTextPlugin.extract({use:'css-loader?sourceMap',fallback:'style-loader'})},
            {test: /\.json$/, loader:'json-loader'},
            {test: /\.(png|jpg|ico|gif)$/,loader: 'url-loader?limit=8192&name=../img/[hash:8].[name].[ext]'}
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {NODE_ENV: JSON.stringify(process.env.NODE_ENV|| 'development'),},
        }),
        new webpack.optimize.UglifyJsPlugin({
            output: {comments: false,},
            compress: {warnings: false},
            sourceMap: true,
        }),
        new webpack.BannerPlugin('version 1.0.0 by yfx.'),//在生成的文件中加入注释插件
        new ExtractTextPlugin({filename:"../css/style.min.css",allChunks: true}),//压缩css,并单独打包
        new webpack.optimize.CommonsChunkPlugin({names:['vendor']}),
    ],
    devtool: process.env.NODE_ENV==='production'?"source-map":"inline-source-map",//source-map当不为production时开启
    resolve: {// 现在你require文件的时候可以直接使用require('file')，不用使用require('file.coffee')
        extensions: ['.js','.es6','.jsx', '.json','.less','.css']
    }
};